﻿package mortal.game.view.LineOffReward.item
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.LineOffReward.data.*;
    import mortal.game.view.common.*;
    import mortal.game.view.task.data.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;

    public class LineOffCopyCell extends GCellRenderer
    {
        public var _bg:ScaleBitmap;
        public var _itemPic:GImageBitmap;
        public var _copyName:GTextFiled;
        public var _coinBtn:GLoadingButton;
        public var _godBtn:GLoadingButton;
        public var _seventTxt:GTextFiled;
        public var _tenTxt:GTextFiled;
        public var _timeDes:GTextFiled;
        public var _getTipBg:GBitmap;
        public var _splitLine:ScaleBitmap;
        public var _titleDesLeft:GBitmap;
        public var _titleDesRight:GBitmap;
        protected var _need:GTextFiled;
        private var _reTxtArr:Array;
        private var _info:SCopyCompensation;
        private var _obj:Object = null;
        private var sp:GSprite;

        public function LineOffCopyCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 331, 130, this, ImagesConst.LineOffCopyCellBg);
            this._itemPic = UIFactory.gImageBitmap("230000002.jpg", 19, 30, this);
            this._copyName = UIFactory.gTextField("", 4, 4, 340, 25, this);
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.color = 16777215;
            _loc_1.size = 14;
            _loc_1.align = "center";
            this._copyName.defaultTextFormat = _loc_1;
            this._copyName.setTextFormat(_loc_1);
            this._seventTxt = UIFactory.gTextField("", 103, 99, 70, 20, this);
            var _loc_2:* = GlobalStyle.textFormatLv;
            this._seventTxt.defaultTextFormat = _loc_2;
            this._seventTxt.setTextFormat(_loc_2);
            this._tenTxt = UIFactory.gTextField("", 258, 99, 100, 20, this);
            var _loc_3:* = GlobalStyle.textFormatHuang;
            this._tenTxt.defaultTextFormat = _loc_3;
            this._tenTxt.setTextFormat(_loc_3);
            this._timeDes = UIFactory.gTextField("", 85, 31, 200, 20, this);
            var _loc_4:* = GlobalStyle.textFormatHuang;
            this._timeDes.defaultTextFormat = _loc_4;
            this._timeDes.setTextFormat(_loc_4);
            this._getTipBg = UIFactory.gBitmap(ImagesConst.LineOffCopyGotTipBg, 144, 35, this);
            this._godBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 184, 97, 75, 25, this);
            this._godBtn.label = "" + Language.getString(71700);
            this._coinBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 28, 97, 75, 25, this);
            this._coinBtn.label = "" + Language.getString(71701);
            this._splitLine = UIFactory.bg(83, 89, 243, 2, this, ImagesConst.SplitLine3);
            this._titleDesLeft = UIFactory.gBitmap(ImagesConst.TitleLine, 40, 13, this);
            this._titleDesRight = UIFactory.gBitmap(ImagesConst.TitleLine, 309, 13, this);
            this._titleDesRight.scaleX = -1;
            this._need = UIFactory.gTextField("", 211, 31, 120, 20, this);
            this._coinBtn.drawNow();
            this._godBtn.drawNow();
            this._getTipBg.visible = false;
            this._coinBtn.configEventListener(MouseEvent.CLICK, this.onBtnCkHd);
            this._godBtn.configEventListener(MouseEvent.CLICK, this.onBtnCkHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.clear();
            this._bg.dispose(param1);
            this._itemPic.dispose(param1);
            this._copyName.dispose(param1);
            this._coinBtn.dispose(param1);
            this._godBtn.dispose(param1);
            this._seventTxt.dispose(param1);
            this._tenTxt.dispose(param1);
            this._timeDes.dispose(param1);
            this._getTipBg.dispose(param1);
            this._splitLine.dispose(param1);
            this._titleDesLeft.dispose(param1);
            this._titleDesRight.dispose(param1);
            this._bg = null;
            this._itemPic = null;
            this._copyName = null;
            this._coinBtn = null;
            this._godBtn = null;
            this._seventTxt = null;
            this._tenTxt = null;
            this._timeDes = null;
            this._getTipBg = null;
            this._splitLine = null;
            this._titleDesLeft = null;
            this._titleDesRight = null;
            this._need = null;
            if (this.sp)
            {
                this.sp.dispose();
                this.sp = null;
            }
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            super.selected = param1;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._info = param1 as SCopyCompensation;
            this.clear();
            if (this._info == null)
            {
                return;
            }
            this._timeDes.text = "" + Language.getStringByParam(71702, this._info.count);
            this._copyName.text = "" + this.getCopyName();
            this.updateRewards();
            this.showGray(this._info.count == 0);
            this.updateNeedNum();
            this.updateVIPAndGold();
            return;
        }// end function

        private function getCopyName() : String
        {
            var _loc_1:* = LineOffRewardConfig.instance.lineOffCopyReward[this._info.copyCode];
            if (_loc_1 && _loc_1.taskCode != 0)
            {
                return TaskRule.getGroupFullName(_loc_1.taskCode);
            }
            var _loc_2:* = CopyConfig.instance.getCopyInfoByCode(_loc_1.copyCode);
            if (_loc_2)
            {
                return _loc_2.name;
            }
            return "" + Language.getString(71703);
        }// end function

        private function updateRewards() : void
        {
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            this._reTxtArr = [];
            var _loc_1:* = this._info.count;
            var _loc_2:* = LineOffRewardConfig.instance.lineOffCopyReward[this._info.copyCode];
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:int = 1;
            var _loc_4:String = "";
            if (_loc_2.exp > 0)
            {
                _loc_4 = _loc_4 + (Language.getString(71704) + _loc_2.exp * _loc_1);
                this.genTxt(_loc_4, _loc_3);
                _loc_3++;
            }
            var _loc_5:int = 1;
            while (_loc_5 <= 3)
            {
                
                if (_loc_2.hasOwnProperty("unit" + _loc_5) == false)
                {
                }
                else
                {
                    _loc_6 = int(_loc_2["unit" + _loc_5]);
                    _loc_7 = int(_loc_2["count" + _loc_5]) * _loc_1;
                    if (_loc_7 > 0)
                    {
                        _loc_4 = GameDefConfig.instance.getEPrictUnitName(_loc_6);
                        _loc_4 = _loc_4 + ("：" + _loc_7);
                        this.genTxt(_loc_4, _loc_3);
                    }
                    _loc_3++;
                }
                _loc_5++;
            }
            if (_loc_2 && _loc_2.hasOwnProperty("icon"))
            {
                this._itemPic.imgUrl = _loc_2["icon"] + ".jpg";
            }
            return;
        }// end function

        private function genTxt(param1:String, param2:int) : void
        {
            var _loc_3:GTextFiled = null;
            _loc_3 = UIFactory.gTextField(param1, 0, 0, 150, 20, this);
            _loc_3.x = 109 + (param2 - 1) % 2 * 110;
            _loc_3.y = 48 + int((param2 - 1) / 2) * 20;
            var _loc_4:* = GlobalStyle.textFormatBai;
            _loc_4.size = 13;
            _loc_3.setTextFormat(_loc_4);
            _loc_3.defaultTextFormat = _loc_4;
            this._reTxtArr.push(_loc_3);
            return;
        }// end function

        public function updateOneCell(param1:SCopyCompensation) : Boolean
        {
            if (this._info && this._info.copyCode == param1.copyCode)
            {
                this._info.count = param1.count;
                if (this._info.count == 0)
                {
                    this.showGray(true);
                }
                return true;
            }
            else
            {
                return false;
            }
        }// end function

        private function clear() : void
        {
            var _loc_1:int = 0;
            var _loc_2:GTextFiled = null;
            if (this._reTxtArr)
            {
                _loc_1 = 0;
                while (_loc_1 < this._reTxtArr.length)
                {
                    
                    _loc_2 = this._reTxtArr[_loc_1];
                    _loc_2.dispose();
                    _loc_1++;
                }
                this._reTxtArr = null;
            }
            this.showGray(false);
            return;
        }// end function

        private function onBtnCkHd(event:MouseEvent) : void
        {
            var _loc_7:int = 0;
            if (this._info == null)
            {
                return;
            }
            var _loc_2:int = 0;
            var _loc_3:String = "";
            this._obj = null;
            var _loc_4:int = 0;
            var _loc_5:* = LineOffRewardConfig.instance.lineOffCopyReward[this._info.copyCode];
            _loc_3 = GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoin);
            _loc_4 = _loc_5.coin * this._info.count;
            if (event.currentTarget == this._godBtn)
            {
                _loc_7 = Cache.instance.lineOff.vipType;
                _loc_2 = 2;
                _loc_4 = _loc_5.gold * this._info.count;
                _loc_3 = GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitGold);
            }
            else
            {
                _loc_2 = 1;
                _loc_4 = _loc_5.coin * this._info.count;
                _loc_3 = GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoin);
            }
            this._obj = {};
            this._obj.copyCode = this._info.copyCode;
            this._obj.type = _loc_2;
            this._obj.num = _loc_4;
            var _loc_6:* = Language.getStringByParam(71706, _loc_4 + _loc_3);
            TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.LineOffGetReward, this.getCallback, _loc_6, null, Alert.OK | Alert.CANCEL);
            return;
        }// end function

        private function updateNeedNum() : void
        {
            if (this._info == null)
            {
                return;
            }
            var _loc_1:int = 0;
            var _loc_2:* = LineOffRewardConfig.instance.lineOffCopyReward[this._info.copyCode];
            _loc_1 = _loc_2.coin * this._info.count;
            this._need.text = Language.getStringByParam(71707, _loc_1);
            return;
        }// end function

        private function getCallback() : void
        {
            if (this._obj.type == 1 && Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitCoinBind, this._obj.num) == false)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShowBindCoinPackWin, this._obj.num));
                return;
            }
            if (this._obj)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LineOffRewardGetCopyOne, this._obj));
            }
            return;
        }// end function

        private function showGray(param1:Boolean) : void
        {
            if (param1)
            {
                this.sp = UIFactory.getUICompoment(GSprite);
                this.addChild(this.sp);
                this.sp.graphics.clear();
                this.sp.graphics.beginFill(0, 0.5);
                this.sp.graphics.drawRect(2, 2, this.width - 2, this.height - 2);
                this.sp.graphics.endFill();
                this._getTipBg.visible = true;
                this.addChild(this._getTipBg);
            }
            else
            {
                if (this.sp)
                {
                    this.sp.dispose();
                    this.sp = null;
                }
                this._getTipBg.visible = false;
            }
            var _loc_2:* = !param1;
            var _loc_3:* = _loc_2;
            this._godBtn.enabled = _loc_2;
            this._coinBtn.enabled = _loc_3;
            return;
        }// end function

        private function updateVIPAndGold() : void
        {
            var _loc_5:int = 0;
            var _loc_1:* = VipConfig.instance.getValueByTypeAndLv(EVipRecordType._EVipRecordTypeResourceBack, Cache.instance.vip.level);
            var _loc_2:* = int(_loc_1);
            var _loc_3:* = Cache.instance.vip.level;
            if (_loc_2 > 0)
            {
                this._coinBtn.label = Language.getStringByParam(71708, _loc_3);
                this._seventTxt.text = Language.getStringByParam(71709, _loc_2);
            }
            else
            {
                this._coinBtn.label = "" + Language.getString(71710);
                this._seventTxt.text = "" + Language.getString(71711);
            }
            var _loc_4:* = LineOffRewardConfig.instance.lineOffCopyReward[this._info.copyCode];
            if (_loc_4 && _loc_4.gold != 0)
            {
                _loc_5 = Cache.instance.lineOff.vipType;
                if (VipUtil.isVipReachLevelByType(_loc_5))
                {
                    var _loc_6:Boolean = true;
                    this._tenTxt.visible = true;
                    this._godBtn.visible = _loc_6;
                    this._godBtn.enabled = true;
                    this._tenTxt.text = Language.getStringByParam(71709, 100 + _loc_2);
                    this._godBtn.filters = null;
                }
                else
                {
                    var _loc_6:Boolean = true;
                    this._tenTxt.visible = true;
                    this._godBtn.visible = _loc_6;
                    this._godBtn.enabled = false;
                    this._godBtn.filters = [FilterConst.colorFilter2];
                    this._tenTxt.text = Language.getStringByParam(71712, VipUtil.getVipMinLevelByType(_loc_5));
                }
            }
            else
            {
                var _loc_6:Boolean = false;
                this._tenTxt.visible = false;
                this._godBtn.visible = _loc_6;
                this._tenTxt.text = "" + Language.getString(71713);
                this._godBtn.filters = null;
            }
            return;
        }// end function

    }
}
